package ar.com.angrymachine.hunter.activities;

import java.awt.Graphics;
import java.awt.Rectangle;

import ar.com.angrymachine.hunter.GraphicStyles;
import ar.com.angrymachine.hunter.Locale;
import ar.com.angrymachine.hunter.gameplay.Room;

public class CollapsingExploreActivity extends ExploreActivity
{
	private int collapseTime;
	private int currentCollapseTime = 0;
    public CollapsingExploreActivity(Room room, int explorationTime, int collapseTime)
    {
    	super(room, explorationTime);
    	this.collapseTime = collapseTime;
    }
    
    public String getActionText()
    {
        if(isCompleted())
        {
        	if(currentCollapseTime >= collapseTime)
        	{
        		return Locale.COLLAPSED;
        	}
        	else
        	{
        		return Locale.EXPLORED;
        	}
        }
        else
        {
            if(isRunning())
            {
                return Locale.EXPLORING;
            }
            else
            {
                return Locale.EXPLORE;    
            }
        }
    }
    
    public boolean isCompleted()
    {
        return currentExploration >= maxExploration || currentCollapseTime >= collapseTime;
    }

    public void update(int delta, boolean action, boolean timeIsRunning)
    {
    	super.update(delta, action, timeIsRunning);
        if(timeIsRunning)
        {
        	currentCollapseTime += delta;
            if(currentCollapseTime >= collapseTime)
            {
            	end(true);
            }
        }
    }

    public void paint(Graphics g, Rectangle activityArea)
    {
        GraphicStyles.paintDefaultActivity(g, this, activityArea, room.icon);
        if(!isCompleted())
        {
        	Rectangle bar = GraphicStyles.getBarArea(activityArea);
        	g.setColor(GraphicStyles.collapseBarColor());
            GraphicStyles.paintLabeledBar(g, Locale.COLLAPSING, bar, currentCollapseTime, collapseTime);
        }
    }
}
